package demo;

import helloword.MyService;
import org.apache.thrift.server.TNonblockingServer;
import org.apache.thrift.server.TThreadedSelectorServer;
import org.apache.thrift.transport.TNonblockingServerSocket;
import org.apache.thrift.transport.TNonblockingServerTransport;
import org.apache.thrift.transport.TTransportException;


/**
 *
 */
public class NioServer {

    public static void main(String[] args) throws TTransportException {

        TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(8080);
        TThreadedSelectorServer.Args serverArgs = new TThreadedSelectorServer.Args(serverTransport);
        MyHandler myHandler = new MyHandler();
        MyService.Processor<MyHandler> processor = new MyService.Processor<>(myHandler);
        serverArgs.processor(processor);
        TThreadedSelectorServer selectorServer = new TThreadedSelectorServer(serverArgs);
        selectorServer.serve();
//
//


//        //单线程mode
//        TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(8080);
//        TNonblockingServer.Args serverArgs = new TNonblockingServer.Args(serverTransport);
//        MyHandler myHandler = new MyHandler();
//        MyService.Processor<MyHandler> processor = new MyService.Processor<>(myHandler);
//        serverArgs.processor(processor);
//        TNonblockingServer nonblockingServer = new TNonblockingServer(serverArgs);
//        nonblockingServer.serve();
    }
}
